﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Churchtoolkit.Utils.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:Notification runat=server></{0}:Notification>")]
    public class Notification : WebControl
    {
        private bool _isShown;
        private string _message;
        public Notification()
            : base(HtmlTextWriterTag.Div)
        {

        }

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string DefaultText
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "notification");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "visible");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Position, "fixed");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Cursor, "pointer");
            base.RenderBeginTag(writer);
        }
        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write(string.IsNullOrEmpty(this._message) ? DefaultText : _message);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (_isShown)
                base.Render(writer);
        }

        public void Show(string message)
        {
            this._isShown = true;
            this._message = message;
        }
        public void Show()
        {
            this._isShown = true;
        }
    }
}
